<?php
	class SystemAccessLogsController extends Controller
	{
		public $page_title = LANG_SYSTEM_ACCESS_LOGS;
		public $layout = 'main';
		public $module = 'administration';
		public $helpers = array ('html', 'htmlx', 'toolbars', 'grids');
		public $name = 'system_access_logs';		
		public $menuItem = 'systemaccesslogs';		
		public $use_logging = false;
		
		/**
		 * Manages the tables logs settings
		 */
		function Edit()
		{
			//updates for new tables
			$this->controller_model->Update('', 'sp_system_access_logs_insert');
			
			$this->data['accesses_logs'] = $this->controller_model->ListItems();
			
			if (!empty($this->request->post))
			{
				$this->SaveAccessLogs($this->request->post);
				$this->Redirect($this->name.'/edit/');
			}
			else
			{

			}	
		}

		/**
		 * Displays the access logs settings
		 */
		function View()
		{
			$this->data['accesses_logs'] = $this->controller_model->ListItems();
		}

		/**
		 * Saves the data
		 * @param array $data
		 */
		private function SaveAccessLogs($data)
		{
			$is_logged_list = '0';
			$is_commented_list = '0';
			foreach ($data['access_logs'] as $key => $value)
			{
				if ($value['is_logged'] == 1) $is_logged_list = $is_logged_list.', '.$key;
				if ($value['is_commented'] == 1) $is_commented_list = $is_commented_list.', '.$key;
			}
			$this->controller_model->Update(array('is_logged_list' => $is_logged_list, 'is_commented_list' => $is_commented_list), 'sp_system_access_logs_update_list');
		}
	}
?>